<style>
	.priority_high{
		border-right: 3px solid rgb(255, 0, 0);
		width: 0px;
	}
	.priority_medium{
		border-right: 3px solid rgb(0, 204, 102);
		width: 0px;
	}
	.priority_low{
		border-right: 3px solid rgb(255, 255, 0);
		width: 0px;
	}
	.priority_none{
		background-color: #fff;
		width: 0px;
	}
	td div { position: relative; }
</style>

<?php 
$previous_month 	= ($month_id - 1);
$next_month		 = ($month_id + 1);
$d = '20'.$year_id;
$num = cal_days_in_month(CAL_GREGORIAN, $month_id , $d );
?>
<ul class="pager">
<?php if($previous_month > 0) {?>
  <li class="previous">
    <a href="<?php echo site_url('user/to_do/view_all/1/'.$previous_month.'/'.$year_id)?>">&larr; Previous Month</a>
  </li>
  <?php } if($next_month <= 12) {?>
  <li class="next">
    <a href="<?php echo site_url('user/to_do/view_all/1/'.$next_month.'/'.$year_id)?>">Next Month &rarr;</a>
  </li>
  <?php }?>
</ul>

<div class="pagination" style="font-size: 9px;">
  <ul>
    <?php 	
	for($i=1;$i<=$num;$i++) {?>    
	<li	<?php if($date_id == $i){ echo 'class="active"'; }?> ><a href="<?php echo site_url('user/to_do/view_all/'.$i.'/'.$month_id.'/'.$year_id)?>"><?php echo $i?></a></li>
	<?php }?>
  </ul>
</div>

<h3>All To Do For <?= date("F", mktime(0, 0, 0, $month_id, 10))?> - <?= $date_id?></h3>
<form action="<?php echo site_url('user/to_do/save')?>" method="POST">
<div class="row-fluid">
	<div class="span2">
	<input type="text" class="span12 datepicker" name="date" value="<?php echo date('Y-m-d')?>"/>	
	</div>
	<div class="span2">
	<select name="user_id" class="span12 chzn-select" >
			<option value="0">-- Select User --</option>
			<?php foreach($users as $user){
				if( !($this->ion_auth->is_client($user->id)) AND ($this->ion_auth->is_active($user->id)) ){	
				?>
			<option value="<?php echo $user->id;?>" 
			<?php if($user->id == $this->session->userdata('user_id')){ ?>
			<?php echo 'selected="selected"' ?>
			<?php }?>
			>
			<?php if($user->id == $this->session->userdata('user_id')){ ?>
			<?php echo 'Me' ?>
			<?php }else{ 
			echo $user->username;
			}?>			
			</option>			
			<?php }}?>			
		</select>				
	</div>
	<div class="span6">
		<input type="text" class="span12" name="desc"/>
	</div>
	<div class="span2">
		<input type="submit" value="Add ToDo" class="btn btn-success"/>
	</div>
</div>
</form>
<hr />
<?php 
$msg = $this->session->flashdata('msg');
if(!empty($msg)){?>
	<div class="alert alert-success">
	<button type="button" class="close" data-dismiss="alert">&times;</button>
	<?php echo $msg;?></div>
<?php }?>

<table class="table table-condensed table-bordered table-striped" width="80%">
<thead>
<tr>
	<th>Name</th>
	<th>ToDo List</th>	
</tr>
</thead>
	<?php foreach($users as $user){ 

	if( !($this->ion_auth->is_client($user->id)) AND ($this->ion_auth->is_active($user->id)) ){	
	?>	
	<tr>
		<td width="12%">
		<a href="<?php echo site_url('user/to_do/view/'.$user->id.'/'.$month_id.'/'.$year_id)?>">
		<?php echo $user->username;?>
		</a>	
		</td>
		<td width="100%">
			<table class="table table-condensed table-bordered table-striped">
			
			<?php $fav_todos = $this->todo_model->fav_todo_all($date_id,$month_id,$year_id,$user->id);
				foreach($fav_todos as $pt){?>
				<tr>
				<td width="3%"  <?php if(($pt->priority=="high")){echo 'class="priority_high"' ;}elseif(($pt->priority=="medium")){echo 'class="priority_medium"';}elseif(($pt->priority=="low")){ echo 'class="priority_low"';}else{ echo 'class="priority_none"';} ?>>
					<?php if($pt->is_completed == 0) {?>
					 <a href="<?php echo site_url('user/to_do/complete/'.$pt->id);?>"><i class="icon-ok-circle muted"></i></a>
					 <?php }else {?>
					 <a href="<?php echo site_url('user/to_do/incomplete/'.$pt->id);?>"><i class="icon-ok-sign text-success"></i></a>
					 <?php }?>
				</td>
					<td width="87%">
					<span <?php if($pt->is_completed == 1) {?>
					style="text-decoration: line-through;"					
					<?php }?> >  <?php echo $pt->des?>
						</span>
					</td>
					<td width="3%">			
					<a href="#" onclick="rem_fav(<?php echo $pt->id?>)"><i class="icon-star"></i></a> 					
				</td>
					<td width="7%">
					<div class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cogs"></i>
  <b class="caret"></b>
  </a>
					<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
						
						<?php if(!$this->ion_auth->is_admin($this->session->userdata('user_id'))){?> 
					 	<li><a href="<?php echo site_url('user/to_do/worksheet/'.$pt->id);?>" class="add_worksheet"><i class="icon-plus text-error"></i> <span class="text-error"> Add To Worksheet</span> </a></li>
						<?php }?>
												
						<li><a href="<?php echo site_url('user/to_do/get_todo/'.$pt->id);?>" class="get_todo"><i class="icon-edit"></i> Edit ToDo </a></li>	
						<li><a href="javascript:void(0)" onclick="delete_todo(<?php echo $pt->id?>)"><i class="icon-trash"></i> Delete </a></li>
					 </ul>
					</div>						
					</td>
				</tr>
				<?php }?>
		<?php 
		$date_id=date('d');
		$month_id=date('m');
		$year_id=date('y');
			$todo = $this->todo_model->todo_all($date_id,$month_id,$year_id,$user->id);			
			foreach($todo as $td){		
			?>
			<tr>
			<td width="3%" <?php if(($td->priority=="high")){echo 'class="priority_high"' ;}elseif(($td->priority=="medium")){echo 'class="priority_medium"';}elseif(($td->priority=="low")){ echo 'class="priority_low"';}else{ echo 'class="priority_none"';} ?>>
					<?php if($td->is_completed == 0) {?>
					 <a href="<?php echo site_url('user/to_do/complete/'.$td->id);?>"><i class="icon-ok-circle muted"></i></a>
					 <?php }else {?>
					 <a href="<?php echo site_url('user/to_do/incomplete/'.$td->id);?>"><i class="icon-ok-sign text-success"></i></a>
					 <?php }?>
				</td>
				<td width="87%">
					<span <?php if($td->is_completed == 1) {?>
					style="text-decoration: line-through;"					
					<?php }?> >  <?php echo $td->des?>
						</span>
					</td>
					<td width="3%"></td>
					<td width="7%">
					<div class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cogs"></i>
  <b class="caret"></b>
  </a>
					 <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
					 <li><a href="#" onclick="add_fav(<?php echo $td->id?>)"><i class="icon-star"></i> Add to Fav </a></li>					 	
						<li><a href="<?php echo site_url('user/to_do/get_todo/'.$td->id);?>" class="get_todo"><i class="icon-edit"></i> Edit ToDo </a></li>	
						<li><a href="javascript:void(0)" onclick="delete_todo(<?php echo $td->id?>)"><i class="icon-trash"></i> Delete </a></li>
					 </ul>
					</div>
					
					</td>
			</tr>	
			<?php }?>
			</table>
		</td>
	</tr>
	<?php }}?>	
</table>
<script type="text/javascript">
<!--
	function delete_todo(Id){									
		$.post('<?= site_url("user/to_do/delete");?>',{id:Id}, function(replies) {			
			location.reload();  		
	});
}

function add_to_subtask(des){
		$.post('<?= site_url("user/to_do/");?>',{des:des}, function(replies) {			
			location.reload();  		
	});
	}	
$('.get_todo').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});
function add_fav(Id){	
	$.post('<?= site_url("user/to_do/add_fav");?>',{id:Id}, function(replies) {			
			location.reload();  		
	});
}

function rem_fav(Id){
	$.post('<?= site_url("user/to_do/rem_fav");?>',{id:Id}, function(replies) {			
			location.reload();  		
	});
}	
	
//-->
</script>
